package avicit.im.lantop.basic.archivetemplatemanager.service.api;


import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ArchivetemplatemanagerServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/archivetemplatemanager/rest/ArchivetemplatemanagerServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     *获取归档模板信息
     * @param project
     * @param orgId
     * @return
     */
    public List<Map<String, Object>> selectPlan(String project, String orgId) {
        String url = BASE_PATH + "/selectPlan";
        Map<String,Object> map = new HashMap<>();
        map.put("project",project);
        map.put("orgId",orgId);
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 查询计划下所有项目信息
     * @param planName
     * @return
     */
    public List<Map<String, Object>> selectProject(String planName) {
        String url = BASE_PATH + "/selectProject";
        Map<String,Object> map = new HashMap<>();
        map.put("planName",planName);
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *更新项目信息
     * @param planId
     * @param planNameto
     * @return
     */
    public Map<String, Object> updateProjct(String planId, String planNameto) {
        String url = BASE_PATH + "/updateProjct";
        Map<String,Object> map = new HashMap<>();
        map.put("planId",planId);
        map.put("planNameto",planNameto);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *新增项目信息
     * @param orgId
     * @param deptId
     * @param sysId
     * @param projectNameNew
     * @param commitTypeto
     * @param planId
     * @param count
     * @return
     */
    public Map<String, Object> saveProject(String orgId, String deptId, String sysId, String projectNameNew, String commitTypeto, String planId, Integer count) {
        String url = BASE_PATH + "/saveProject";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("deptId",deptId);
        map.put("sysId",sysId);
        map.put("projectNameNew",projectNameNew);
        map.put("commitTypeto",commitTypeto);
        map.put("planId",planId);
        map.put("count",count);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 删除计划信息
     * @param idVal
     */
    public void deletePlan(String idVal) {
        String url = BASE_PATH + "/deletePlan";
        Map<String,Object> map = new HashMap<>();
        map.put("idVal",idVal);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
    }


    /**
     * 新增归档模板计划
     * @param orgId
     * @param deptId
     * @param sysId
     * @param planName
     * @param type
     * @param o
     * @param i
     * @return
     */
    public Map<String, Object> savePlan(String orgId, String deptId, String sysId, String planName, String type, Object o, int i) {
        String url = BASE_PATH + "/savePlan";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("deptId",deptId);
        map.put("sysId",sysId);
        map.put("planName",planName);
        map.put("type",type);
        map.put("o",o);
        map.put("i",i);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *
     * @param id
     * @param page
     * @param rows
     * @return
     */
    public Map<String, Object> selectProjectList(String id, Integer page, Integer rows) {
        String url = BASE_PATH + "/selectProjectList";
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("page",page);
        map.put("rows",rows);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
